# from __future__ import absolute_import, unicode_literals
import json

from celery import shared_task
import time


from tools.IdentityCard import idc
from tools.myredis import r
from user.views import IdCardView
<<<<<<< HEAD

from tools.bdapi import bdapi
from tools.myredis import r

=======
from tools.bdapi import bdapi
from tools.myredis import r
>>>>>>> 6ae99858eaddabbed530d3fd9701bae475648410


# @shared_task
# def cheduler_task(name):
#     end = int(time.time()) - 600
#     olist = r.sorted_times(key, 0, end)
#     for i in olist:
#         res = alipay.query_pay(i.decode())
#         requests
#         content = res.text
#         # 更新订单更新用户余额


<<<<<<< HEAD
@shared_task
def bdcardmes():
    # 从redis list中获取10条信息
    # 调用百度api接口
    # 将结果存入redis
    blist = r.list_lrange('baiduurllist', 0, 10)
    if blist:
        for i in blist:
            picurl = i.decode()
            # 调用百度api接口

            mes = bdapi.fontmessage(picurl)

            # 存入redis {"name":"zs","code":"234234"}
            r.set_str(picurl, json.dumps(mes))
            r.list_del('baiduurllist', picurl)


=======
# @shared_task
# def bdcardmes():
#     # 从redis list中获取10条信息
#     # 调用百度api接口
#     # 将结果存入redis
#     blist = r.list_lrange('baiduurllist', 0, 10)
#     if blist:
#         for i in blist:
#             picurl = i.decode()
#             # 调用百度api接口
#             mes = bdapi.fontmessage(picurl)
#             # 存入redis {"name":"zs","code":"234234"}
#             r.set_str(picurl, json.dumps(mes))
#             r.list_del('baiduurllist', picurl)
#
#     print("调用百度api接口")

from celery import Celery
import requests

# 创建 Celery 应用程序
app = Celery('tasks', broker='redis://localhost:6379/0', backend='redis://localhost:6379/0')

# 定义任务函数
@app.task
def call_api():
    url = "http://127.0.0.1:8000/car/test/"  # 替换为实际的接口地址
    try:
        response = requests.get(url)
        if response.status_code == 200:
            print("接口调用成功，响应内容:", response.text)
        else:
            print("接口调用失败，状态码:", response.status_code)
    except Exception as e:
        print("调用接口时发生异常:", str(e))


# 配置定时任务
app.conf.beat_schedule = {
    'call-api-every-minute': {
        'task': 'tasks.call_api',  # 任务名称，根据实际情况修改
        'schedule': 60.0,  # 60 秒执行一次，可根据需要修改
    },
}
>>>>>>> 6ae99858eaddabbed530d3fd9701bae475648410
